@echo off
cd /d D:\OpenSees_GPUSOLVER-main\opensees_gpusolver

echo ========================================
echo Testing CUDA Compilation - All Files
echo ========================================
echo.

set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.0
set NVCC="%CUDA_PATH%\bin\nvcc.exe"
set MSVC_PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702
set GPU_SRC=SRC\system_of_eqn\linearSOE\GPUSolver

REM ========== Test 1: GPUMaterialKernels.cu ==========
echo [1/5] Compiling GPUMaterialKernels.cu...
%NVCC% -c ^
  -gencode=arch=compute_60,code=sm_60 ^
  -rdc=true ^
  -ccbin "%MSVC_PATH%\bin\HostX86\x64" ^
  -I"%CUDA_PATH%\include" ^
  -I"%GPU_SRC%" ^
  -I"SRC" ^
  --machine 64 ^
  -DWIN32 -DNDEBUG ^
  -Xcompiler "/EHsc /W3 /nologo /O2 /MT" ^
  -o test_material.obj ^
  "%GPU_SRC%\GPUMaterialKernels.cu"

if errorlevel 1 (
    echo FAILED: GPUMaterialKernels.cu
    pause
    exit /b 1
)
echo SUCCESS: GPUMaterialKernels.cu
echo.

REM ========== Test 2: GPUElementKernels.cu ==========
echo [2/5] Compiling GPUElementKernels.cu...
%NVCC% -c ^
  -gencode=arch=compute_60,code=sm_60 ^
  -rdc=true ^
  -ccbin "%MSVC_PATH%\bin\HostX86\x64" ^
  -I"%CUDA_PATH%\include" ^
  -I"%GPU_SRC%" ^
  -I"SRC" ^
  --machine 64 ^
  -DWIN32 -DNDEBUG ^
  -Xcompiler "/EHsc /W3 /nologo /O2 /MT" ^
  -o test_element.obj ^
  "%GPU_SRC%\GPUElementKernels.cu"

if errorlevel 1 (
    echo FAILED: GPUElementKernels.cu
    pause
    exit /b 1
)
echo SUCCESS: GPUElementKernels.cu
echo.

REM ========== Test 3: GPUMatrixKernels.cu ==========
echo [3/5] Compiling GPUMatrixKernels.cu...
%NVCC% -c ^
  -gencode=arch=compute_60,code=sm_60 ^
  -rdc=true ^
  -ccbin "%MSVC_PATH%\bin\HostX86\x64" ^
  -I"%CUDA_PATH%\include" ^
  -I"%GPU_SRC%" ^
  -I"SRC" ^
  --machine 64 ^
  -DWIN32 -DNDEBUG ^
  -Xcompiler "/EHsc /W3 /nologo /O2 /MT" ^
  -o test_matrix.obj ^
  "%GPU_SRC%\GPUMatrixKernels.cu"

if errorlevel 1 (
    echo FAILED: GPUMatrixKernels.cu
    pause
    exit /b 1
)
echo SUCCESS: GPUMatrixKernels.cu
echo.

REM ========== Test 4: GPUMatrixAssembly.cu ==========
echo [4/5] Compiling GPUMatrixAssembly.cu...
%NVCC% -c ^
  -gencode=arch=compute_60,code=sm_60 ^
  -ccbin "%MSVC_PATH%\bin\HostX86\x64" ^
  -I"%CUDA_PATH%\include" ^
  -I"%GPU_SRC%" ^
  -I"SRC" ^
  --machine 64 ^
  -DWIN32 -DNDEBUG ^
  -Xcompiler "/EHsc /W3 /nologo /O2 /MT" ^
  -o test_assembly.obj ^
  "%GPU_SRC%\GPUMatrixAssembly.cu"

if errorlevel 1 (
    echo FAILED: GPUMatrixAssembly.cu
    pause
    exit /b 1
)
echo SUCCESS: GPUMatrixAssembly.cu
echo.

REM ========== Test 5: FastVectorOps.cu ==========
echo [5/5] Compiling FastVectorOps.cu...
%NVCC% -c ^
  -gencode=arch=compute_60,code=sm_60 ^
  -ccbin "%MSVC_PATH%\bin\HostX86\x64" ^
  -I"%CUDA_PATH%\include" ^
  -I"%GPU_SRC%" ^
  -I"SRC" ^
  --machine 64 ^
  -DWIN32 -DNDEBUG ^
  -Xcompiler "/EHsc /W3 /nologo /O2 /MT" ^
  -o test_vector.obj ^
  "%GPU_SRC%\FastVectorOps.cu"

if errorlevel 1 (
    echo FAILED: FastVectorOps.cu
    pause
    exit /b 1
)
echo SUCCESS: FastVectorOps.cu
echo.

echo ========================================
echo ALL CUDA FILES COMPILED SUCCESSFULLY!
echo ========================================
echo.
echo Generated object files:
echo   - test_material.obj
echo   - test_element.obj
echo   - test_matrix.obj
echo   - test_assembly.obj
echo   - test_vector.obj
echo.
pause


